<?php
// region 基础变量
define('CONFIG_INI', dirname(__DIR__) . '/config.ini');
define('ROOT_PATH', dirname(__DIR__));
// endregion
// region 自动加载
require_once __DIR__ . '/Autoloader.php';
$auto = [];
require_once dirname(__DIR__) . '/auto.php';
Autoloader::setAutoArray($auto);
spl_autoload_register('Autoloader::loadByNamespace');
// endregion
// region 错误信息
if (intval(Tool::ini('Debug', '0')) == 1) {
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(-1);
} else error_reporting(0);
// endregion
// region Smarty
require_once dirname(__DIR__) . '/lib/smarty/libs/Smarty.class.php';
$smarty = new Smarty();
$smarty->config_dir = ROOT_PATH . 'public/smarty/demo/configs';
$smarty->setTemplateDir(ROOT_PATH . Tool::ini('SMARTY_TEMPLATE_DIR', '/tpl'));
$smarty->setCompileDir(ROOT_PATH . Tool::ini('SMARTY_COMPILE_DIR', '/tpl/cache'));
$smarty->left_delimiter = Tool::ini('SMARTY_LEFT_DELIMITER', '<?');
$smarty->right_delimiter = Tool::ini('SMARTY_RIGHT_DELIMITER', '?>');
// endregion
// region 时区设置
date_default_timezone_set(Tool::ini('Timezone', 'Asia/Shanghai'));
// endregion
// region 路由
$router_link = mb_strlen($_SERVER['QUERY_STRING'])
    ? explode('?' . $_SERVER['QUERY_STRING'], $_SERVER['REQUEST_URI'])[0]
    : $_SERVER['REQUEST_URI'];
if ($router_link === '/') $router_link = '/index';
$router = [];
require_once dirname(__DIR__) . '/router.php';
$next_require = true;
foreach ($router as $router_key => $router_item)
    if (stripos($router_link, $router_key) !== false && is_file(dirname(__DIR__) . '/app' . $router_item)) {
        require_once dirname(__DIR__) . '/app' . "$router_item";
        $next_require = false;
    }
if ($next_require && is_file(dirname(__DIR__) . '/app' . $router_link . '.php'))
    require_once dirname(__DIR__) . '/app' . "$router_link.php";
// endregion
